<!doctype html>

<%@ page import="com.seabook.happy.website.daos.MoodDao"%>
<%@ page import="com.seabook.happy.website.daos.NewsDao"%>
<%@ page
	import="com.seabook.happy.website.services.UserIdentificationService"%>
<%@ page import="com.seabook.happy.website.pojos.Mood"%>
<%@ page import="com.seabook.happy.website.pojos.News"%>
<%@ page import="com.seabook.happy.website.utils.DateUtils"%>
<%@ page import="com.seabook.happy.website.utils.ImageUtils"%>

<%@ page import="java.util.List"%>

<%@ page import="com.google.appengine.api.users.UserService"%>
<%@ page import="com.google.appengine.api.users.UserServiceFactory"%>

<html>
<head>
<meta charset="utf-8" />
<title>Happy Seabook's Personal Web Site</title>
<link rel="stylesheet" href="css/styles.css" />
<script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
</head>
<body>
	<div id="wrapper" class="wrapperStyle">
		<div id="header">
			<div id="nav-div">
				<h3>Navigation Bar!</h3>
				<%
					UserService userService = UserServiceFactory.getUserService();

					if (UserIdentificationService.isSignedIn()) {
				%>
				<a href="<%=userService.createLogoutURL(request.getRequestURI())%>">logout</a>
				&nbsp; Welcome back
				<%=userService.getCurrentUser().getNickname()%>
				!!
				<%
					} else {
				%>
				<a href="<%=userService.createLoginURL(request.getRequestURI())%>">
					Haven't logged in? </a>
				<%
					}
				%>
			</div>
		</div>
		<div id="main">
			<section>
				<h3>Latest Mood:</h3>
				<div id="mood-div" class="section">
					<div id="mood-display-div">
						<%
						MoodDao moodDao = new MoodDao();
						List<Mood> moods = moodDao.listLatestMoods(3);
						for (Mood mood : moods) {
					%>
						<img
							src="<%=ImageUtils.getMoodImageUrls(mood.getMoods()
								.getCategory())%>" />
						&nbsp;
						<%=mood.getMoodMessage()
								+ DateUtils.parseDate(mood.getModifiedDate())%>
						</br>
						<%
						}
					%>
						<a href="listAllMoods.jsp">List all moods</a>
					</div>
					<%
			if (UserIdentificationService.isAdminLoggedIn()) {
		%>
					<form action="/moodUpdateServlet?action=new" method="post">
						<select name="moods-option" size="1">
							<option value="happy">happy</option>
							<option value="soso">soso</option>
							<option value="unhappy">unhappy</option>
						</select>
						<div id="mood-update-div">
							<textarea id="mood-content-id" name="mood-content" rows="3"
								cols="60"></textarea>
							<input type="submit" value="update moods" />
						</div>
					</form>
					<%
			}
		%>
				</div>
			</section>
			<section>
				<h3>Latest News:</h3>
				<div id="news-div" class="section">
					<div id="news-display-div">
						<%
				NewsDao newsDao = new NewsDao();
				List<News> newsList = newsDao.listLatestNews(3);
				for (News news : newsList) {
			%>
						<%=news.getNewsContent().getValue()
						+ DateUtils.parseDate(news.getModifiedDate())%></br>
						<%
				}
			%>
						<a href="listAllNews.jsp">List all news</a>
					</div>
					<%
			if (UserIdentificationService.isAdminLoggedIn()) {
		%>
					<form action="/newsUpdateServlet?action=new" method="post">
						<div id="news-update-div">
							<textarea id="news-content-id" name="news-content" rows="3"
								cols="60"></textarea>
							<script type="text/javascript">
					CKEDITOR.replace('news-content-id', {
						toolbar : 'NewsToolbar'
					});
				</script>
							<input type="submit" value="update news" />
						</div>
					</form>
					<%
			}
		%>
				</div>
			</section>
			<section>
				<div id="blogs">
					<h3>Latest Blogs:</h3>
					Fetch latest entries from Blogs!!</br>
				</div>
			</section>
			<section>
				<div id="comments">
					<h3>Latest Comments:</h3>
					Fetch latest comments from Blogs' Entries!!</br>
				</div>
			</section>
		</div>
		<div id="footer"></div>
	</div>
</body>
</html>